# 前台登录

from base import build_driver,  _YamlHelper
from page import Page


class WebLoginPage(Page):
    web_login_yaml = _YamlHelper().get_config_as_dict('niushop23\\page\\web_login.yaml')['WebLoginPage']

    def web_login_page(self, name, pwd):
        '''
        输入账户密码
        :param name: 登录账户
        :param pwd:  登录密码
        :return:
        '''
        driver = self._driver
        driver.type(self.web_login_yaml['WEBLOGIN_NAME'], name)
        driver.type(self.web_login_yaml['WEBLOGIN_PWD'], pwd)
        driver.click(self.web_login_yaml['WEB_LOGIN'])

    def click(self):
        '''
        点击登录按钮
        :return:
        '''
        driver = self._driver
        driver.click(self.web_login_yaml['WEBLOGIN_BUTTON'])

    def login_text(self):
        '''
        获取登录页面文本
        :return:
        '''
        driver = self._driver
        login_face_text = driver.get_text(self.web_login_yaml['GET_LOGIN_TEXT'])
        return login_face_text

    def login_after_text(self):
        '''
        获取登录后页面文本
        :return:
        '''
        driver = self._driver
        user_name = driver.get_text(self.web_login_yaml['GET_USER_NAME_TEXT'])
        return user_name

    def login_hint_text(self):
        '''
        获取账户密码错误提示文本
        :return:
        '''
        driver = self._driver
        hint_text = driver.get_text(self.web_login_yaml['GET_HINT_TEXT'])
        return hint_text

    def loginout(self):
        '''
        退出登录
        :return:
        '''
        driver = self._driver
        driver.click(self.web_login_yaml['LOGIN_OUT_BUTTON'])

    def move(self):
        '''
        鼠标悬浮
        :return:
        '''
        driver = self._driver
        driver.move_to(self.web_login_yaml['GETMOVE_TO'])

    def close(self):
        '''
        关闭浏览器
        :return:
        '''
        driver = self._driver
        driver.quit()


if __name__ == '__main__':
    driver = build_driver('http://www.localhost/niushop', 'c')
    web_loginpage = WebLoginPage(driver)
    web_loginpage.click()
    web_loginpage.web_login_page('123', '123456')
